package com.eregg.spring.cloud.movie.feign;

import com.eregg.spring.cloud.movie.bean.User;
import feign.hystrix.FallbackFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/**
 * Created by e on 2017/11/9
 *
 * @author <a href="http://eregg.com">eregg</a>
 */
@Component
public class FeignClientFallbackFactory implements FallbackFactory<UserFeignClient> {

    private Logger logger = LoggerFactory.getLogger(getClass());

    @Override
    public UserFeignClient create(Throwable cause) {
        return new UserFeignClient() {
            @Override
            public User findById(Long id) {
                logger.info("fallback; reason was:{}", cause);
                User user = new User();
                user.setId(-1L);
                user.setName("默认用户");
                return user;
            }
        };
    }
}
